/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CaptionToolbar.java
 *
 * Created on 13/09/2011, 07:04:42
 */
package wf.ui.cmps;

import bc.swing.comp.JActionView;
import bc.swing.pfrm.Action;
import bc.swing.pfrm.BaseParamModel;
import java.awt.Color;
import java.util.List;
import javax.swing.Icon;

/**
 *
 * @author bennyl
 */
public class WFToolbar extends javax.swing.JPanel {

    private static final Color DEFAULT_COLOR = new Color(153,153,153);
    private static final Color HIGHLIGHT_COLOR = new Color(120,160,210);
    
    /** Creates new form CaptionToolbar */
    public WFToolbar() {
        initComponents();
        setBackground(DEFAULT_COLOR);
    }

    public void populate(BaseParamModel param){
        setCaption(param.getName());
        setCaptionIcon(param.getIcon());
        setActions(param.getActions());
    }
    
    @Override
    public void setBackground(Color bg) {
        super.setBackground(bg);
        if (gpan != null){
            gpan.setBackground(bg);
        }
    }

    public void setHighlight(boolean h){
        gpan.setBackground((h? HIGHLIGHT_COLOR: DEFAULT_COLOR));
    }
    
    public void setCaption(String caption){
        captionLabel.setText(caption);
    }

    public void setCaptionIcon(Icon icon){
        captionLabel.setIcon(icon);
    }
    
    public String getCaption(){
        return captionLabel.getText();
    }
    
    public Icon getCaptionIcon(){
        return captionLabel.getIcon();
    }
    
    public void setActions(List<Action> actions){
        actionBar.removeAll();
        for (Action a : actions){
            JActionView av = new JActionView(a);
            actionBar.add(av);
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        gpan = new bc.swing.comp.JGradientPanel();
        captionLabel = new javax.swing.JLabel();
        actionBar = new javax.swing.JPanel();

        setLayout(new java.awt.BorderLayout());

        gpan.setBackground(new java.awt.Color(153, 153, 153));
        gpan.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 3, 1, new java.awt.Color(255, 255, 255)));
        gpan.setLayout(new java.awt.GridBagLayout());

        captionLabel.setForeground(new java.awt.Color(255, 255, 255));
        captionLabel.setText("jLabel1");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 5);
        gpan.add(captionLabel, gridBagConstraints);

        actionBar.setOpaque(false);
        actionBar.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
        gpan.add(actionBar, gridBagConstraints);

        add(gpan, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel actionBar;
    private javax.swing.JLabel captionLabel;
    private bc.swing.comp.JGradientPanel gpan;
    // End of variables declaration//GEN-END:variables
}
